package com.xuecheng.orders.domain.model.entity;

import cn.hutool.core.lang.Snowflake;
import com.baomidou.mybatisplus.annotation.*;
import com.xuecheng.orders.domain.model.enums.XcCurrencyEnum;
import com.xuecheng.orders.domain.model.enums.XcOrderStatusEnum;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 
 * </p>
 *
 * @author itcast
 */
@Data
@TableName("xc_pay_record")
public class XcPayRecord implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 本系统支付交易号
     */
    private Long payNo;

    /**
     * 第三方支付交易流水号
     */
    private String outPayNo;

    /**
     * 第三方支付渠道编号
     */
    private String outPayChannel;

    /**
     * 商品订单号
     */
    private Long orderId;

    /**
     * 订单名称
     */
    private String orderName;

    /**
     * 订单总价单位元
     */
    private Float totalPrice;

    /**
     * 币种CNY
     */
    private String currency;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createDate;

    /**
     * 支付状态
     */
    private String status;

    /**
     * 支付成功时间
     */
    private LocalDateTime paySuccessTime;

    /**
     * 用户id
     */
    private String userId;


    public static XcPayRecord buildByOrder(XcOrders orderRecord) {
        XcPayRecord xcPayRecord = new XcPayRecord();
        xcPayRecord.setPayNo(new Snowflake().nextId());
        xcPayRecord.setOrderId(orderRecord.getId());
        xcPayRecord.setOrderName(orderRecord.getOrderName());
        xcPayRecord.setTotalPrice(orderRecord.getTotalPrice());
        xcPayRecord.setCurrency(XcCurrencyEnum.CNY.getDesc());
        xcPayRecord.setCreateDate(orderRecord.getCreateDate());
        xcPayRecord.setStatus(XcOrderStatusEnum.WAIT.getCode());
        xcPayRecord.setUserId(orderRecord.getUserId());

        return xcPayRecord;
    }
}
